<?php echo $this->render('link/header.phtml') ?>

//常用变量初始化
var menuDelUrl=baseUrl+"/link/serverlink/type/del";
var menuEditUrl=baseUrl+"/link/serverlink/type/edit";
var module="link";
var gridTitle="链接列表";
var dataId="link_id";
var link = Ext.data.Record.create([
           {name: 'link_id', type: 'int'},
           {name: 'link_address', type: 'string'},
           {name:'site_type',type:'string'},
           {name:'client_company'},
           {name:'linktype_name',type:'string'},
		   {name: 'link_content', type: 'string'},
           {name: 'link_pr', type: 'string'},
           {name: 'link_keyword_id', type: 'string'},
           {name: 'link_input_date', type: 'string'},
           {name:'keyword_name'},
           {name:'keyword_link'},
           {name:'keyword_pr'}
      ]);
var linktype_combo_store_select=new Ext.data.JsonStore({
																	  url:baseUrl+'/link/serverlinktype',
																	  root:'results',
																	  fields:['linktype_id','linktype_name']
																	  });
linktype_combo_store_select.load();                                                                      
var linktype_combo=new Ext.form.ComboBox({
										 fieldLabel:'链接类型',
										 store:linktype_combo_store_select,										
        								displayField:'linktype_name',
        								valueField :'linktype_id',
										hiddenName:"linktype_id",
        								typeAhead:true,
        								mode:'local',
        								triggerAction:'all',
                                        editable:false,  
        								selectOnFocus:true,
                                        emptyText:"请选择",
                                        listeners:{
                                        	select:function(){
                                            	if(this.value!=''){
                                                	ds.baseParams.where="linktype_id='"+this.value+"'";
                                                }
                                                ds.reload();
                                            }
                                        }
										 }); 
client_combo_store.load();
var client_combo=new Ext.form.ComboBox({
										width:280,
										 fieldLabel:'选择客户',
										 store:client_combo_store,										
        								displayField:'client_host',
        								valueField :'client_id',
										hiddenName:"client_id",
        								typeAhead:true,
        								triggerAction:'all',
                                        queryParam:'client_host',                                                                               
                                        //hideTrigger: true, //隐藏下拉箭头   
										loadingText: '正在加载...',
                                        pageSize:8,
                                        minChars:1,
                                        queryDelay:300,   
                                        mode :'remote',  
        								emptyText:'请选择...',                                       
        								selectOnFocus:true,
                                        resizable:true, 
                                        listeners:{
                                        	select:function(){
                                            if(this.value!=''){  
                                            	ds.baseParams.where="link_client_id='"+this.value+"'";                                            }  
                                            ds.reload();                           	
                                        	}
                                        }
										 });                                                         
var ds=new Ext.data.Store({
							  proxy:new Ext.data.HttpProxy({
									url:baseUrl+'/link/serverlink/'
									}),
							  reader:new Ext.data.JsonReader({
									root:'results',
									totalProperty:'total',
									id:dataId
									},link)
	});		 
//定义列模型
var cm=new Ext.grid.ColumnModel([	
							new Ext.grid.CheckboxSelectionModel(),
                            {header:'链接ID',dataIndex:'link_id',width:60,hidden:true}, 
							{header:'客户',dataIndex:'client_company',width:60},                                                       														
                            {header:'链接类型',dataIndex:'linktype_name',width:60,hidden:true},                           														
                            {header:'目标网站类型',dataIndex:'site_type',width:60,hidden:true},                           														
                            {header:'关键字',dataIndex:'keyword_name',width:200},
                            {header:'TargetPage',dataIndex:'keyword_link',width:200,renderer:show_link},
                            {header:'TargetPage(pr)',dataIndex:'keyword_pr',width:200},							
							{header:'Inbound Link',dataIndex:'link_address',width:220,renderer:show_link},
                            {header:'InLink(pr)',dataIndex:'link_pr',width:200},							
                            {header:'提交时间',dataIndex:'link_input_date',hidden:true,width:200}							
	]);
cm.defaultSortable = true; 



//定义工具栏								 
var tb=new Ext.Toolbar({
							items:[
							<?php if($this->acl->isAllowed($this->role,'link','linkDel')) {?>
                                         {
                                            id:'menuDel'+ExtId,
											text:'删除',
											iconCls:'icn-delete',
											handler:menuDel
											},
                           <? } ?>
                           <?php if($this->acl->isAllowed($this->role,'link','linkAdd')) {?>                
                                            {
                                            text:'添加链接',
											iconCls:'icn-add',
											handler:menuLinkAdd
                                            }
							<? } ?>			
                            	,"-","客户:"	,client_combo,"链接类型:",linktype_combo,{xtype:'tbfill'},
                                {text:'过期且失效的链接',iconCls:'icn-search',handler:menusearch}
								 ]
	});			

function menusearch(){
var start_date='<?=date('Y-m-d h:i:s',time()-86400*30)?>';
var end_date='<?=date('Y-m-d h:i:s')?>';
ds.baseParams.where=" link_isexist=0 and link_input_date between '"+start_date+"' and '"+end_date+"' ";	 
ds.reload();
 } 
function menuLinkAdd(){
         addtab("添加链接",baseUrl+"/link/linkadd",'link_linkadd');
}
function addtab(name,link,id){
	var main=Ext.getCmp('content');
	var tabId="tab_"+id;
	var tabLink=link;
	var tabTitle=name;
	var tab=main.getComponent(tabId);
	var subMainId='tab_'+id+'main';
    if(!tab){
        tab=main.add({
				'id':tabId,
				'title':tabTitle,
				closable:true,
				autoScroll : true ,
				layout : 'fit' ,
				border : false
				//autoLoad:{url:tabLink,scripts:true,nocache:true}
				});        
		main.setActiveTab(tab);  
		var loadmask = new Ext.LoadMask(tab.body,{msg:"页面加载中……"}) ;		
		loadmask.show() ;
		tab.load({
			url: tabLink,
			discardUrl: false,
			//nocache: true,
			timeout: 3000,
			scripts: true,
			text:'',
			callback:function(a,b,c){
				if(b){
					loadmask.hide();
					}
				}
		});
    }
	main.setActiveTab(tab);    
}
<?php echo $this->render('link/foot.phtml') ?>
